package com.xuecheng.media.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.base.exception.XueChengPlusException;
import com.xuecheng.base.model.RestResponse;
import com.xuecheng.media.model.po.MediaFiles;
import com.xuecheng.media.service.MediaFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api("大文件管理相关接口")
@RestController
public class BigFilesController {
    @Autowired
    MediaFileService mediaFileService;

    @ApiOperation("大文件上传前检查文件是否上传")
    @PostMapping("/upload/checkfile")
    public RestResponse<Boolean> checkFile(@RequestParam("fileMd5")String fileMd5){
        return mediaFileService.checkFile(fileMd5);
    }

    @ApiOperation("大文件上传前检查分块文件是否上传")
    @PostMapping("/upload/checkchunk")
    public RestResponse<Boolean> checkChunk(@RequestParam("fileMd5")String fileMd5,
            @RequestParam("chunk")Integer chunk){
        return mediaFileService.checkChunk(fileMd5,chunk);
    }

    @ApiOperation("大文件上传时分块文件上传")
    @PostMapping("/upload/uploadchunk")
    public RestResponse<Boolean> uploadChunk(
            @RequestParam("file")MultipartFile file,
            @RequestParam("fileMd5")String fileMd5,
            @RequestParam("chunk")Integer chunk){
        return mediaFileService.uploadChunk(file,fileMd5,chunk);
    }

    @ApiOperation("大文件上传后合并分块文件")
    @PostMapping("/upload/mergechunks")
    public RestResponse<Boolean> mergeChunks(
            @RequestParam("fileMd5")String fileMd5,
            @RequestParam("fileName")String fileName,
            @RequestParam("chunkTotal")Integer chunkTotal){
        Long companyId = 1232141425L;
        return mediaFileService.mergeChunks(companyId,fileMd5,fileName,chunkTotal);
    }
}
